﻿<UserControl x:Class="UnityEditor.Controls.ProjectControl.ProjectControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:UnityEditor.Controls.ProjectControl.ViewModel"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
             x:Name="projectControl"
             d:DesignHeight="300" 
             d:DesignWidth="300"
             AllowDrop="True"
             DragEnter="TreeView_DragEnter"
             DragOver="TreeView_DragOver"
             Drop="TreeView_Drop"
             PreviewMouseMove="TreeView_PreviewMouseMove"
             PreviewMouseLeftButtonDown="TreeView_PreviewMouseLeftButtonDown">

    <UserControl.Resources>
        <local:FileToIconConverter x:Key="ProjectItemIconConverter"/>
        <ContextMenu x:Key="TreeItemContextMenu">
            <MenuItem Header="Open In Explorer" Click="OpenInExplorer_Click"/>
            <MenuItem Header="Create" Click="CreateMenuItem_Click"/>
            <MenuItem Header="Rename" Click="RenameMenuItem_Click"/>
            <MenuItem Header="Delete" Click="DeleteMenuItem_Click"/>
        </ContextMenu>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Orientation="Horizontal">
            <xctk:DropDownButton x:Name="_dropDownButton"
                              HorizontalAlignment="Left"
                              Content="Menu">
                <xctk:DropDownButton.DropDownContent>
                    <StackPanel>
                        <Menu>
                            <Menu.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel Orientation="Vertical"/>
                                </ItemsPanelTemplate>
                            </Menu.ItemsPanel>
                            
                            <MenuItem Header="Create New Folder" Click="CreateMenuItem_Click"/>
                            <MenuItem Header="Refresh" Click="Refresh_Click"/>
                        </Menu>
                    </StackPanel>
                </xctk:DropDownButton.DropDownContent>
            </xctk:DropDownButton>
            <TextBox Width="240" Margin="0"/>
        </StackPanel>

        <!-- TreeView with FolderView into FileSystem -->
        <TreeView x:Name="TreeView" Grid.Row="1"  Margin="3,3,3,3"
                  ItemsSource="{Binding Children}"
                  TreeViewItem.Expanded="TreeView_Expanded"
                  TreeViewItem.Selected="TreeView_Selected">

            <TreeView.ItemContainerStyle>
                <!-- This Style binds a TreeViewItem to a TreeItem. -->
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="FontWeight" Value="Normal" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>

            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource ="{Binding Children}">
                    <StackPanel Orientation="Horizontal"
                                ContextMenu="{StaticResource TreeItemContextMenu}">
                        <Image Height="16" Width="16" Source="{Binding Converter={StaticResource ProjectItemIconConverter}}"/>
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</UserControl>
